package com.luoxiang.socialandroid.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.bean.SelectResult;
import com.luoxiang.socialandroid.bean.THost;
import com.luoxiang.socialandroid.utils.CustomClickListener;

import java.util.List;

public class SelectipAdapter extends RecyclerView.Adapter<SelectipAdapter.ViewHolder> {
    private List<SelectResult> list;

    public SelectipAdapter(List<SelectResult> list) {
        this.list = list;
    }

    public static interface OnAddClickListener {
        void onItemClicks(String quhao);
    }

    SelectipAdapter.OnAddClickListener onItemAddClick;


    public void setOnAddClickListener(SelectipAdapter.OnAddClickListener onItemAddClick) {
        this.onItemAddClick = onItemAddClick;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_selectip, parent, false);
        SelectipAdapter.ViewHolder holder = new SelectipAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.textView30.setText(list.get(position).getCountry());
        holder.tvQuhao.setText(list.get(position).getMobile_prefix());
        holder.itemView.setOnClickListener(new CustomClickListener() {
            @Override
            protected void onSingleClick() {
                onItemAddClick.onItemClicks(list.get(position).getMobile_prefix());
            }

            @Override
            protected void onFastClick() {

            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView30, tvQuhao;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            textView30 = itemView.findViewById(R.id.textView30);
            tvQuhao = itemView.findViewById(R.id.tvQuhao);
        }
    }
}
